#pragma once

#include <iostream>
#include <ctime>
#include <cstdarg>

enum level
{
    Debug = 0,
    Normal,
    Warning,
    Error,
};

std::string LevelToString(int level)
{
    switch (level)
        {
        case Debug:
            return "Debug";
        case Normal:
            return "Normal";

        case Warning:
            return "Warning";

        case Error:
            return "Error";

        default:
            return "Don't Know";
        }
}

void LogMessage(int level, const char *format, ...)
{
    va_list args;
    va_start(args, format);

    char buffer[1024];
    vsnprintf(buffer, sizeof(buffer), format, args);
    va_end(args);

    //获取时间
    time_t current_time;  
    struct tm *now_time;  
      
    // 获取当前时间的时间戳  
    current_time = time(NULL);  
      
    if (current_time == -1) {  
        perror("Error getting time");  
        return;
    }  
      
    // 将时间戳转换为本地时间  
    now_time = localtime(&current_time);  

    // 打印信息
    printf("[%s]  [%04d-%02d-%02d %02d:%02d:%02d]  [%s]\n", LevelToString(level).c_str(), now_time->tm_year + 1900, now_time->tm_mon + 1, now_time->tm_mday,
                    now_time->tm_hour, now_time->tm_min, now_time->tm_sec, buffer);
}